package basic.thread.student;

public class SetStudentThread implements Runnable {
	private Student student;
	private int x;

	public SetStudentThread(Student student) {
		this.student = student;
	}

	@Override
	public void run() {
		while (x < 20) {
			synchronized (student) {
				if (student.flag) {
					try {
						student.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				if (x % 2 == 0) {
					student.setName("aa");
					student.setAge(10);
				}

				else {
					student.setName("cc");
					student.setAge(20);
				}
				x++;
				student.notify();
				student.flag = true;

			}

		}

	}

}
